// import nvService from '@/api/NvService'
import { nvServiceSilent } from '@/api/NvService'
import cacheManage from '@/cache/CacheManage'
// import { ElMessage } from 'element-plus'
export default class DataSource {
  constructor (config) {
    this.sourceName = config.name;
    this.nv = null;
    this.nvs = [];
    this.config = config;
    this.success = false;
  }

  async queryData(config) {
    this.sourceName = config.name;
    if (config.functionName === 'getNvByCode') {
      const codeFdName = config.codeFdName;
      const code = config.code;
      if (!code) {
        this.nv = null;
        this.success = true;
      }
      const ndCode = config.ndCode;
      const commonInfo = cacheManage.getDefaultCommonInfo();
      const msg = await nvServiceSilent.getNvByCode(commonInfo, ndCode, code, codeFdName);
      if (msg.success) {
        this.nv = msg.value;
        this.success = true;
      } else {
        this.nv = null;
        this.success = false;
      }
    }
  }

  getNv() {
    if (!this.success) {
      // ElMessage({
      //   type: 'error',
      //   message: `获取实例失败，ndCode:${this.config.ndCode},nvCode:${this.config.code}`,
      //   showClose: true
      // })
      return null;
    }
    return this.nv;
  }
}
